package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class WindowPolice extends JFrame implements ActionListener{
	private static final long serialVersionUID = 4174621914605686809L;

	JTextField text1;
	JTextField text2;
	
	public WindowPolice() {
		init();
		setBounds(100, 100, 350, 110);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	void init() {
		setLayout(new FlowLayout());
		text1 = new JTextField(10);
		text2 = new JTextField(10);
		text1.addActionListener(this);
		add(text1);
		add(text2);
		text1.addActionListener((e) -> { //一个监视器
			String string = text1.getText();
			if (string.equalsIgnoreCase("Exit")) {
				System.exit(0);
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) { //另一个监视器
		String string = text1.getText();
		int n = 0;
		int m = 0;
		try {
			n = Integer.parseInt(string);
			m = n * n * n;
			text2.setText("" + m);
		} catch (Exception ee) {
			text2.setText("请输入数字字符");
			text1.setText(null);
		}
		
	}
	
}
